﻿<Window x:Class="Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Water tank demo" 
        xmlns:VM="clr-namespace:Demo"
        xmlns:Converters="clr-namespace:Demo.Converters">
    <Window.Resources>
        <Converters:BooleanToBrush x:Key="BooleanToBrush" />
        <Converters:NumberToPercentage x:Key="VolumePercentageConverter" />
        <Converters:IPAddressToString x:Key="IPAddressToStringConverter" />
        <Converters:NotBoolean x:Key="NotBooleanConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter1" />
    </Window.Resources>
    <Window.DataContext>
        <VM:WaterTankViewModel/>
    </Window.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Viewbox>
            <Canvas Name="Plant" Width="909" Height="829">
                <Canvas Name="Pipes">
                    <Canvas.RenderTransform>
                        <TranslateTransform X="112.1811" Y="22.4375" />
                    </Canvas.RenderTransform>
                    <Path Fill="#FF647687" StrokeThickness="15">
                        <Path.Data>
                            <PathGeometry Figures="M-60.125,-22.4375L-60.125,367.46875 -60.125,367.56245 -60.125,367.62495C-59.929683,376.92887 -61.175797,389.66589 -57.5625,401.43745 -55.755851,407.32323 -52.424116,413.19442 -46.78125,417.2812 -41.165603,421.34826 -33.720535,423.31727 -24.75,423.1562 -24.70652,423.15542 -24.66855,423.15708 -24.625,423.1562L45.71875,423.1562 45.71875,415.6562 53.3125,415.6562 53.3125,415.5625 53.3125,407.96875 45.71875,407.96875 -24.75,407.96875 -24.84375,407.96875 -24.90625,407.96875C-31.61659,408.10467 -35.425922,406.74246 -37.875,404.96875 -40.324078,403.19504 -41.883527,400.70785 -43.03125,396.96875 -45.315467,389.52712 -44.725906,377.94234 -44.9375,367.46875L-44.9375,367.3125 -44.9375,-22.4375 -60.125,-22.4375z" />
                        </Path.Data>
                    </Path>
                    <Path Fill="#FF647687" StrokeThickness="15" >
                        <Path.Data>
                            <PathGeometry FillRule="Nonzero" Figures="M127.19701,407.99117L127.19701,423.01953 127.19701,423.01953 127.19701,423.01953 174.58312,423.01953C174.58312,418.01108,174.58312,412.99962,174.58312,407.99117z" />
                        </Path.Data>
                    </Path>
                    <Path Fill="#FF647687" Name="path389794" Canvas.Left="-39">
                        <Path.Data>
                            <PathGeometry FillRule="Nonzero" Figures="M569.21014,683.2337L569.21014,698.26206 569.21014,698.26206 569.21014,698.26206 603.46427,698.26206C603.46427,693.25361,603.46427,688.24215,603.46427,683.2337z" />
                        </Path.Data>
                    </Path>
                    <Path Fill="#FF647687" Name="path3897948" Canvas.Left="-33">
                        <Path.Data>
                            <PathGeometry FillRule="Nonzero" Figures="M684.84263,683.2337L684.84263,698.26206 684.84263,698.26206 684.84263,698.26206 827.66819,698.26206C827.66819,693.25361,827.66819,688.24215,827.66819,683.2337z" />
                        </Path.Data>
                    </Path>
                </Canvas>
                <Grid Name="WaterTank" Canvas.Left="286" Canvas.Top="336" Width="360" Height="426">
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="356"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Rectangle Width="360" Height="426" StrokeThickness="35" Stroke="Black" Canvas.Left="286" Canvas.Top="336" Grid.RowSpan="3" />
                    <Rectangle Name="WaterLevel" Fill="{StaticResource WaterBrushKey}" Grid.Row="1" Margin="35,0" VerticalAlignment="Bottom" Height="356">
                        <Rectangle.LayoutTransform>
                            <ScaleTransform ScaleY="{Binding Path=WaterLevel.Value, Converter={StaticResource VolumePercentageConverter}}"/>
                        </Rectangle.LayoutTransform>
                    </Rectangle>
                    <TextBlock Grid.Row="1" Text="{Binding Path=WaterLevel.Value, StringFormat=\{0:P0\}, Converter={StaticResource VolumePercentageConverter}}" FontSize="90" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="DodgerBlue" />
                </Grid>
                <Viewbox Name="LevelMinimum" Canvas.Left="546" Canvas.Top="666" Width="50">
                    <Path Fill="{Binding Path=MinimumLevel.Value, Converter={StaticResource BooleanToBrush}}" Stroke="#FF000000" StrokeThickness="5" Data="{StaticResource CircularIndicator}"></Path>
                </Viewbox>
                <Viewbox Name="LevelMaximum" Width="50" Canvas.Left="546" Canvas.Top="388">
                    <Path Stroke="#FF000000" StrokeThickness="5" Fill="{Binding Path=MaximumLevel.Value, Converter={StaticResource BooleanToBrush}}" Data="{StaticResource CircularIndicator}" Canvas.Left="798" Canvas.Top="211"></Path>
                </Viewbox>
                <Grid Name="WaterTemperature" Canvas.Left="276" Canvas.Top="91" Height="148" Width="393">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Water Temperature" FontSize="32" TextAlignment="Center" Grid.ColumnSpan="2" Grid.Column="1" FontWeight="Normal" />
                    <Path Name="path4" Fill="Black" Stretch="Uniform" Margin="10,20" Grid.RowSpan="2">
                        <Path.Data>
                            <PathGeometry Figures="M623.01541,161.28811C623.01541,170.29244 615.71614,177.59171 606.71181,177.59171 597.70749,177.59171 590.40822,170.29244 590.40822,161.28811 590.40822,153.29609 596.15864,146.64719 603.74752,145.25338L603.74752,107.93088 609.67611,107.93088 609.67611,145.25338C617.26499,146.64748,623.01541,153.29609,623.01541,161.28811z M633.39043,161.28811C633.39043,176.02242 621.44582,187.96673 606.71181,187.96673 591.97751,187.96673 580.0332,176.02242 580.0332,161.28811 580.0332,150.8132 586.06998,141.7484 594.85465,137.38289L594.85465,81.25256C594.85465,74.70385 600.1631,69.3954 606.71181,69.3954 613.26023,69.3954 618.56898,74.70385 618.56898,81.25256L618.56898,137.38259C627.35336,141.7481,633.39043,150.8132,633.39043,161.28811z M600.78323,141.39743C592.21199,143.9485 585.96178,151.88835 585.96178,161.28811 585.96178,172.74806 595.25187,182.03815 606.71181,182.03815 618.17176,182.03815 627.46155,172.74806 627.46155,161.28811 627.46155,151.88835 621.21135,143.9485 612.6404,141.39743L612.6404,81.25256C612.6404,77.97821 609.98587,75.32398 606.71181,75.32398 603.43746,75.32398 600.78323,77.97821 600.78323,81.25256L600.78323,141.39743z M591.89036,78.28798L591.89036,81.25227 574.10462,81.25227 574.10462,78.28798 591.89036,78.28798z M591.89036,87.18085L591.89036,90.14514 580.0332,90.14514 580.0332,87.18085 591.89036,87.18085z M591.89036,96.07372L591.89036,99.03801 574.10462,99.03801 574.10462,96.07372 591.89036,96.07372z M591.89036,104.96659L591.89036,107.93088 580.0332,107.93088 580.0332,104.96659 591.89036,104.96659z M591.89036,113.85946L591.89036,116.82375 574.10462,116.82375 574.10462,113.85946 591.89036,113.85946z M591.89036,122.75234L591.89036,125.71663 580.0332,125.71663 580.0332,122.75234 591.89036,122.75234z M591.89036,131.64521L591.89036,134.6095 574.10462,134.6095 574.10462,131.64521 591.89036,131.64521z" />
                        </Path.Data>
                    </Path>
                    <TextBlock FontSize="64" FontWeight="Bold" Text="{Binding Path=WaterTemperature.Value, StringFormat=\{0:F1\}}" Grid.Column="1" Grid.Row="1" TextAlignment="Right" Margin="0,0,30,0"></TextBlock>
                    <TextBlock FontSize="64" FontWeight="Bold" Name="textBlock2" Text="ºC" Grid.Column="2" Grid.Row="1" />
                </Grid>
                <Viewbox Name="OutletValve" Width="100" Canvas.Left="672" Canvas.Top="619">
                    <Path Fill="{Binding Path=OutletValve.Value, Converter={StaticResource BooleanToBrush}}" Stroke="#FF000000" StrokeThickness="25" Canvas.Left="686" Canvas.Top="532" Data="{StaticResource Valve}"></Path>
                </Viewbox>
                <Viewbox Name="InletValve" Canvas.Left="149" Canvas.Top="344" Width="100">
                    <Path Fill="{Binding Path=InletValve.Value, Converter={StaticResource BooleanToBrush}}" Stroke="#FF000000" StrokeThickness="25" Data="{StaticResource Valve}"></Path>
                </Viewbox>
            </Canvas>

        </Viewbox>
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Background="#FF030303">
            <TextBlock Text="PLC IP:" TextAlignment="Center" FontSize="48" VerticalAlignment="Center" Foreground="White" />
            <TextBox Text="{Binding Path=IP, Converter={StaticResource IPAddressToStringConverter}}" FontSize="48" VerticalContentAlignment="Center"  IsEnabled="{Binding Path=Connected, Converter={StaticResource NotBooleanConverter}}" Width="363" TextAlignment="Center" />
            <Button  Command="{Binding Path=ToggleConnection}" >
                <Grid>
                    <ContentControl Content="{StaticResource appbar_connect}"></ContentControl>
                    <ContentControl Content="{StaticResource appbar_disconnect}" Visibility="{Binding Path=Connected, Converter={StaticResource BooleanToVisibilityConverter1}}"></ContentControl>
                </Grid>
            </Button>
        </StackPanel>
    </Grid>
</Window>
